#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

typedef int ElementType;
typedef struct HEAP Heap;
struct HEAP {
	ElementType *elm;
	int max_size;
	int size;
};

Heap *initHeap(int);
_Bool insertHeap(Heap*,ElementType);
_Bool heapFull(Heap *h);
void printHeap(Heap *);
void printPath(Heap *,int);

int main(void){
	Heap *h=initHeap(10000);
	int nums,times;
	scanf("%d %d",&nums,&times);
	ElementType key;
	for(int i=0;i<nums;i++){
		scanf("%d",&key);
		insertHeap(h,key);
	}
//printHeap(h);
	int index;
	for(int i=0;i<times;i++){
		scanf("%d",&index);
		printPath(h,index);
	}
	return 0;
}

Heap *initHeap(int max_size){
	Heap *ret=malloc(sizeof(Heap));
	ret->elm=malloc(sizeof(ElementType)*(max_size+1));
	ret->max_size=max_size;
	ret->size=0;
	ret->elm[0]=INT_MIN;
	return ret;
}

_Bool heapFull(Heap *h){
	if( h->size == h->max_size )
		return true;
	return false;
}

_Bool insertHeap(Heap* h,ElementType elm){
	if( heapFull(h) )
		return false;
	int i=++h->size;
	for( ; elm < h->elm[i/2] ; i=i/2){
		h->elm[i]=h->elm[i/2];
	}
	h->elm[i]=elm;
	return true;
}

void printHeap(Heap *h){
	for(int i=1;i <= h->size;i++){
		printf("%d ",h->elm[i]);
	}
	return;
}

void printPath(Heap *h,int index){
	_Bool first=true;
	while( index <= h->size && index!=0 ){
		if( first ){
			printf("%d",h->elm[index]);
			first=false;
		}else{
			printf(" %d",h->elm[index]);
		}
		index/=2;
	}
	printf("\n");
	return;
}
